//
//  StatusCell.swift
//  SinaWeiBo
//
//  Created by dengchen on 15/11/14.
//  Copyright © 2015年 name. All rights reserved.
//

import SnapKit
import UIKit

let CellMargins:CGFloat = 6
let CellIconSize: CGFloat = 50

class StatusCell: UITableViewCell {

    
    var status:statusModel? {
        didSet {
            OriginalView.status = status
            setupBottomView()
        }
    }
    
    var bottomConstraints:Constraint?
    
    private func setupBottomView() {
        
        self.bottomConstraints?.uninstall()
        
        //判断是否这条微博数据是否含有转发微博,有和没有都要做出对应的处理防止重用
        if let ret = status?.retweeted_status {
            
            retView.hidden = false
            retView.retStatus = ret
            
            BottomView.snp_updateConstraints(closure: { (make) -> Void in
                self.bottomConstraints = make.top.equalTo(retView.snp_bottom).constraint
            })
            
        }else {
            
            retView.hidden = true
            
            BottomView.snp_updateConstraints(closure: { (make) -> Void in
                self.bottomConstraints = make.top.equalTo(OriginalView.snp_bottom).constraint
            })
        }
    }
    
    override init(style: UITableViewCellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        setupUI()
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
  
    
    private func setupUI() {
    
        selectionStyle = .None
        
        contentView.addSubview(OriginalView)
        contentView.addSubview(retView)
        contentView.addSubview(BottomView)
        
        OriginalView.snp_makeConstraints { (make) -> Void in
            make.top.left.right.equalTo(contentView)
        }
        
        retView.snp_makeConstraints { (make) -> Void in
            make.top.equalTo(OriginalView.snp_bottom)
            make.left.right.equalTo(contentView)
        }
        
        BottomView.snp_makeConstraints { (make) -> Void in
//            make.height.equalTo(30)
            make.left.right.equalTo(contentView)
        self.bottomConstraints =  make.top.equalTo(retView.snp_bottom).constraint
        }
        
        contentView.snp_makeConstraints { (make) -> Void in
            make.bottom.equalTo(BottomView)
            make.top.left.right.equalTo(self)
        }
        
    }
    
  private let OriginalView = StatusOriginalView()
    
    
  private let BottomView = StatusCellBottomView()
    
    //转发微博
  private let retView = retweetedView()
    
}
